/*
 * Copyright (c) 2024. hallele, Inc All rights reserved.
 */

package cn.hallele.ms.portalcenter.domain.das;

import cn.hallele.infrastructure.util.ObjectUtil;
import cn.hallele.ms.infrastructure.core.convertor.das.ModelDas;
import cn.hallele.ms.portalcenter.domain.domain.RoleMenuDomain;
import cn.hallele.ms.portalcenter.model.cache.RoleMenuCache;
import cn.hallele.ms.portalcenter.model.entity.RoleMenuEntity;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.List;

/**
 * hallele_ms_portalcenter
 *
 * @author anle5
 * @since 2024/10/6 13:51
 */
@Slf4j
@Service
public class RoleMenuDEDas extends ModelDas<RoleMenuCache, RoleMenuDomain, RoleMenuEntity> {
    protected RoleMenuDEDas(RoleMenuCache option) {
        super(option);
    }

    /**
     * 查询某个用户的权限
     *
     * @param roleIds roleIds
     * @return List
     */
    public List<RoleMenuDomain> findByRoleIdIn(Collection<Integer> roleIds) {
        return revertList(this.option.findByRoleIdIn(roleIds));
    }

    /**
     * 将T转成E
     *
     * @param roleMenuDomain 被转换者
     * @return S 转换后者
     */
    @Override
    protected RoleMenuEntity convert(RoleMenuDomain roleMenuDomain) {
        return ObjectUtil.map(roleMenuDomain, u -> RoleMenuEntity.builder()
                .id(u.getId())
                .roleId(u.getRoleId())
                .menuId(u.getMenuId())
                .createTime(u.getCreateTime())
                .build());
    }

    /**
     * 将E回转陈T
     *
     * @param roleMenuEntity 被回转换者
     * @return S 回转换后者
     */
    @Override
    protected RoleMenuDomain revert(RoleMenuEntity roleMenuEntity) {
        return ObjectUtil.map(roleMenuEntity, u -> RoleMenuDomain.builder()
                .id(u.getId())
                .roleId(u.getRoleId())
                .menuId(u.getMenuId())
                .createTime(u.getCreateTime())
                .build());
    }
}
